'use strict';

const Controller = require('egg').Controller;

class OrderController extends Controller {
  async list() {
    let page = this.ctx.request.body.page ? parseInt(this.ctx.request.body.page) : 1
    let limit = parseInt(this.ctx.request.body.limit);
    console.log(page, limit)
    let offset = (page - 1) * limit;
    const res = await this.app.model.Order.findAll({
      offset,
      limit,
      include:[{
        model:this.app.model.User,
  
        attributes:["id","username","avatar"]

      }]
    })
    let count = await this.app.model.Order.count();
    console.log(count, "count")
    let obj = {
      data: res,
      count: count
    }
    this.ctx.apiSuccess(
      obj, "获取成功", 200
    )
    
  }
  async delete(){
    this.ctx.validate({
      id:{  type: "int",
        required: false,
        defValue: "",
        desc: "id",
        
      },
    })
    let res=this.app.model.Order.destroy({
      where:{
        id:this.ctx.request.body.id
      }
    })
    this.ctx.apiSuccess(res,"删除成功",200)
  }
}

module.exports = OrderController;
